// 把一个数组分割成想要的数组长度
export const splitArr = (data, num) => {
  const arr = []
  const len = data.length
  for (let i = 0; i < len; i += num) {
    arr.push(data.slice(i, i + num))
  }
  return arr
}

// 处理提示类型
export const handleMessage = (type) => {
  let message = ''
  const select = [
    'select',
    'radio',
    'checkbox',
    'timePoint',
    'inputMap',
    'selectPlus'
  ]
  const input = ['input', 'textarea']
  const upload = ['upload', 'filePreview']
  if (select.findIndex((x) => type === x) !== -1) {
    message = '请选择'
  }
  if (input.findIndex((x) => type === x) !== -1) {
    message = '请输入'
  }
  if (upload.findIndex((x) => type === x) !== -1) {
    message = '请上传'
  }
  return message
}

// 匹配正则
export const findPattern = (item) => {
  const obj = {}
  if (!item.pattern) {
    obj.message = ''
    obj.pattern = /[\s\S]*/
  } else {
    obj.message = `${item.label}格式不正确`
    obj.pattern = item.pattern
  }
  return obj
}
